package edu.bbu.bibliospring.wsclient;

import edu.bbu.bibliospring.backend.model.Book;
import edu.bbu.bibliospring.backend.service.AuthorService;
import edu.bbu.bibliospring.backend.model.Author;
import edu.bbu.bibliospring.backend.service.BookService;

import javax.naming.InitialContext;
import java.util.Hashtable;

public class Main {
	
	public static void main(final String[] args) {

        System.out.println("app successfully started.");

        try {
            System.out.println("Main class started.");

            final InitialContext ic = new InitialContext();
            System.out.println("Initial context created.");

            final AuthorService authorService = (AuthorService) ic.lookup("java:global/bibliospring-server-0.0.1-SNAPSHOT/bibliospring-backend-0.0.1-SNAPSHOT/AuthorService");
            System.out.println("AuthorService instantiated.");

            final BookService bookService = (BookService) ic.lookup("java:global/bibliospring-server-0.0.1-SNAPSHOT/bibliospring-backend-0.0.1-SNAPSHOT/BookService");
            System.out.println("BookService instantiated.");

            final Author author = new Author("Hrabal", "Bohumil");
            authorService.insertAuthor(author);
            System.out.println("author = " + author.toString());
            System.out.println("author.getFirstName() = " + author.getFirstName());
            System.out.println("author.getLastName() = " + author.getLastName());

            final Book book = new Book();
            book.setTitle("Ostře sledované vlaky");
            book.setYearOfPublishing(1978l);
            book.setEditor("Akademie");
            book.setAuthor(author);
            bookService.insertBook(book);
            System.out.println("book.toString() = " + book.toString());
            System.out.println("book.getTitle() = " + book.getTitle());

         } catch (Exception e) {
            e.printStackTrace();
        }
	}

}
